<template>
    <div class="bars" :style="{ width: w }">
        <div class="bar" v-for="item in vols.vols" :style="getStyle(item)">
            <!-- <div class="color" :style="getSubStyle(item)"></div> -->
            <!-- <div class="w">{{ Number(item.t).toFixed(2) }}</div> -->
        </div>
    </div>
</template>

<script lang="ts" setup>
import { Bus, CHART_KLINE_SUBSCRIBE } from '@/connetion/Bus';
import { useVols } from '@/stores/vols';
import { onMounted, ref } from 'vue';

const vols = useVols();
const w = ref("100%");
const getStyle = (item: any) => {
    let w;
    if(item.t == 0){
        w = 0;
    }
    else{
        w = (item.b / item.t) * 100;
    }
    return {
        width: item.w + "px",
        height: item.h + "px",
        top: item.y + "px",
        w: w + "%"
    }
}

const getSubStyle = (item: any) => {
    let w;
    if(item.t == 0){
        w = 0;
    }
    else{
        w = (item.b / item.t) * 100;
    }
    return {
        width: w + "%"
    }
}
onMounted(() => {
    onChange();
    window.addEventListener("resize", onChange);
    Bus.on(CHART_KLINE_SUBSCRIBE, onChange);
})

const onChange = ()=>{
    resize();
    setTimeout(resize, 300);
    setTimeout(resize, 900);
    setTimeout(resize, 1800);
}

const resize = () => {
    // console.log("vols.vols", vols.vols)
    let dom: any = document.getElementById("candle_pane");
    if(!dom) return;
    w.value = dom!.firstChild.clientWidth + 'px';
}
</script>

<style lang="less" scoped>
.bars {
    width: 100%;
    height: 100%;
    position: absolute;
    z-index: 8;
    pointer-events: none;
    top: 0;
    left: 0;
    overflow: hidden;

    .bar {
        background: rgba(9, 98, 231, 0.5);
        position: absolute;
        right: 0;
        font-size: 12px;
        display: flex;
        justify-content: flex-end;
        .color{
            height: 100%;
            background: rgba(3, 172, 121, 0.5);
        }
        .w{
            position: absolute;
            left: 10px;
            top: 0;
            height: 100%;
            display: flex;
            align-items: center;
            color: #fff;
            font-size: 12px;
        }
    }
}
</style>